﻿using System;
using System.Linq;

namespace SimbaRGVMonitor.Common.Linq
{
    public static class TypeExtension
    {
        public static bool IsNotPublicClass(this Type nowType)
        {
            return
                nowType.IsClass &&
                nowType.IsNotPublic &&
                nowType.IsAbstract == false;
        }

        public static bool IncludeZeroaryConstructor(this Type nowType)
        {
            return nowType
                    .GetConstructors()
                    .Any(info => info.GetParameters().Length == 0);
        }

        //====================================================================================================
        //以上是构造方式判别
        //----------------------------------------------------------------------------------------------------
        //以下是继承关系判别
        //====================================================================================================

        public static bool DerivedFromClass<TClass>(this Type nowType)
        {
            return nowType.IsSubclassOf(typeof(TClass));
        }

        public static bool IncludeInterface<TInterface>(this Type nowType)
        {
            return nowType
                    .GetInterfaces()
                    .Any(currentInterfaceType => currentInterfaceType == typeof(TInterface));
        }
    }
}
